package main

import (
  "fmt"
)

var a int = 100

func testGlobalVariable(){
  fmt.Printf("a=%d\n",a) //100
}

//代码块级别作用域
func testLocalVariable() {
  var b int = 100
  fmt.Printf("a=%d b=%d\n",a,b)

  if b == 100 {
    var c int = 200//c只在花括号内有用
    fmt.Printf("c=%d\n",c)
  }
  //fmt.Printf("c=%d\n",c) //Unresolved reference 'c'

  if d := 100;d> 0 {
    fmt.Printf("d=%d\n",d)
  } else{
    fmt.Printf("else d=%d\n",d)
  }
  //fmt.Printf("d=%d\n",d) //Unresolved reference 'd'

  for i := 0; i < 10; i++ {
    fmt.Printf("i=%d\n",i)
  }
  //fmt.Printf("i=%d\n",i) //Unresolved reference 'i'




  fmt.Printf("a=%d\n",a) //100
  var a = 1000
  fmt.Printf("a=%d\n",a) //1000
}

//todo 包级别作用域

func main() {
  //testGlobalVariable()

  testLocalVariable()
}

